package com.ylx.web.y;

import com.ylx.pojo.User;
import com.ylx.pojo.Time;
import com.ylx.service.UserService;
import com.ylx.service.UserServiceIpml;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Calendar;

@WebServlet("/selectUserServlet")
public class SelectUserServlet extends HttpServlet {
    private UserService userService=new UserServiceIpml();
    protected void doPost (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        User user2 = (User) request.getSession().getAttribute("us");




        String uid = request.getParameter("uid");
        User user = userService.selectUserByUid(uid);
        Calendar calendar = Calendar.getInstance();
        String t = Time.getDateFormat(calendar.getTime(),"yyyy-MM-dd HH:mm:ss");
        request.setAttribute("t",t);
        request.setAttribute("user1",user2);
        request.setAttribute("user",user);
        HttpSession session = request.getSession();
        session.setAttribute("user",user);
        request.getRequestDispatcher("/selectsServlet").forward(request,response);

    }

    protected void doGet (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doPost(request, response);

    }
}
